package com.hfzy.ihk.common.util;

import java.io.IOException;

/**
 * Created by Administrator on 2019/1/15.
 *
 * @author wws
 */
public class KeyTool {

    public static void main(String[] args) throws Exception
    {



    }

    static void genServerKey() throws IOException {
        // 所有变量都是写死的， 可以自己修改
        // 生成证书
        String doscmd = null;
        doscmd = "keytool -genkey " +
                "-alias casserver " +
                "-keyalg RSA " +
                "-keysize 2048 " +
                "-keypass changeit " +
                "-storepass changeit " +
                "-keystore D:\\JavaSolution\\keyTool\\casserver.keystore " +
                "-dname \"CN=cas.server.org,OU=cas.server.org,O=casserver,L=casserver,ST=casserver,C=CN\" " +
                "-deststoretype pkcs12";
//        String[] paramArrayOfString = doscmd.split("\\s+");
        Runtime.getRuntime().exec(doscmd);

    }
    static void casserverExportKey() throws IOException {
        // 所有变量都是写死的， 可以自己修改
        // 生成证书
        String doscmd = null;
        // 导出证书
        doscmd = "keytool -export " +
                "-keystore  D:\\JavaSolution\\keyTool\\casserver.keystore " +
                " -alias   casserver  " +
                "-file  D:\\JavaSolution\\keyTool\\casserver.cer " +
                "-storepass changeit ";
//        paramArrayOfString = doscmd.split("\\s+");
        Runtime.getRuntime().exec(doscmd);
    }

    static void genClientKey() throws IOException {
        // 所有变量都是写死的， 可以自己修改
        // 生成证书
        String doscmd = null;
        doscmd = "keytool -genkey " +
                "-alias casclient " +
                "-keyalg RSA " +
                "-keysize 2048 " +
                "-keypass changeit " +
                "-storepass changeit " +
                "-keystore D:\\JavaSolution\\keyTool\\casclient.keystore " +
                "-dname \"CN=cas.client.org,OU=cas.client.org,O=casclient,L=casclient,ST=casclient,C=CN\" " +
                "-deststoretype pkcs12";
//        String[] paramArrayOfString = doscmd.split("\\s+");
        Runtime.getRuntime().exec(doscmd);

    }
    static void casClientExportKey() throws IOException {
        // 所有变量都是写死的， 可以自己修改
        // 生成证书
        String doscmd = null;
        // 导出证书
        doscmd = "keytool -export " +
                "-keystore  D:\\JavaSolution\\keyTool\\casclient.keystore " +
                " -alias   casclient  " +
                "-file  D:\\JavaSolution\\keyTool\\casclient.cer " +
                "-storepass changeit ";
//        paramArrayOfString = doscmd.split("\\s+");
        Runtime.getRuntime().exec(doscmd);
    }

}
